//
//  OosOfferQuery.m
//  oos4ios
//
//  Created by Pablo Gonzalez on 9/20/11.
//  Copyright 2011 11870.com. All rights reserved.
//

#import "OosOfferQuery.h"
#import <oos4ios/ApiUrlProvider.h>

@implementation OosOfferQuery

static NSString *const OFFER_ID_KEY = @"offerId";
static NSString *const OFFER_EMAIL_KEY = @"email";
static NSString *const OFFER_USER_SLUG_KEY = @"userSlug";

+ (OosOfferQuery *) query 
{
    NSString *urlString = [[ApiUrlProvider provider].offers url];
    NSURL *url = [NSURL URLWithString:urlString];
    return [OosOfferQuery queryWithFeedURL:url];
}

+ (OosOfferQuery *)queryFromUserSlug:(NSString *)slug 
{
    NSString *urlString = [[ApiUrlProvider provider].userOffers getUrl:slug, nil];
    NSURL *url = [NSURL URLWithString:urlString];
    return [OosOfferQuery queryWithFeedURL:url];
}

+ (OosOfferQuery *)queryFromServiceSlug:(NSString *)slug
{
    NSString *urlString = [[ApiUrlProvider provider].siteOffers getUrl:slug, nil];
    NSURL *url = [NSURL URLWithString:urlString];
    return [OosOfferQuery queryWithFeedURL:url];
}

+ (OosOfferQuery *)queryFromOfferId:(NSString *)offerId
{
    NSString *urlString = [[ApiUrlProvider provider].offers getUrl:offerId, nil];
    NSURL *url = [NSURL URLWithString:urlString];
    return [OosOfferQuery queryWithFeedURL:url];
}

- (void) packStore:(OosOptionsStore *)store
{
	[super packStore:store];
    OosOfferOptions *offerOptions = store.offerOptions;
    self.offerId = offerOptions.offerId;
    self.email = offerOptions.email;
    self.userSlug = offerOptions.userSlug;
}

- (NSString *) offerId
{
	return [self valueForParameterWithName: OFFER_ID_KEY];
}

- (void) setOfferId:(NSString *) offerId
{
	[self addCustomParameterWithName:OFFER_ID_KEY value:offerId];
}

- (NSString *)email
{
    return [self valueForParameterWithName:OFFER_EMAIL_KEY];
}

- (void)setEmail:(NSString *)email
{
    [self addCustomParameterWithName:OFFER_EMAIL_KEY value:email];
}

- (NSString *)userSlug
{
    return [self valueForParameterWithName:OFFER_USER_SLUG_KEY];
}

- (void)setUserSlug:(NSString *)userSlug
{
    [self addCustomParameterWithName:OFFER_USER_SLUG_KEY value:userSlug];
}

@end
